/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package at.granul.gephi.shpexporter.ui;
import java.io.File;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
import javax.swing.filechooser.FileFilter;
import org.gephi.data.attributes.api.AttributeColumn;
/**
*
* @author SeidlR
*/
public class SHPExporterDialog extends javax.swing.JDialog {
boolean ok = false;
AttributeColumn[] nodeColums;
AttributeColumn[] geoFields;
public SHPExporterDialog(AttributeColumn[] nodeColums, AttributeColumn[] geoFields) {
super(new JFrame(), "SHP Export Options", true);
initComponents();
this.nodeColums = nodeColums;
this.geoFields = geoFields;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
fakeRealGroup = new javax.swing.ButtonGroup();
fileChooser = new javax.swing.JFileChooser();
realCoordinatesRadioButton = new javax.swing.JRadioButton();
fakeCoordinatesRadioButton = new javax.swing.JRadioButton();
jLabel2 = new javax.swing.JLabel();
longitudeComboBox = new javax.swing.JComboBox();
jLabel3 = new javax.swing.JLabel();
latitudeComboBox = new javax.swing.JComboBox();
jSeparator1 = new javax.swing.JSeparator();
filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0));
filler2 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
filler3 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
fileChooser.setApproveButtonToolTipText(org.openide.util.NbBundle.getMessage(SHPExporterDialog.class, "SHPExporterDialog.approveButtonToolTipText")); // NOI18N
fileChooser.setCurrentDirectory(null);
fileChooser.setDialogTitle(org.openide.util.NbBundle.getMessage(SHPExporterDialog.class, "SHPExporterDialog.dialogTitle")); // NOI18N
fileChooser.setName(""); // NOI18N
fileChooser.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fileChooserAction(evt);
}
});
fakeRealGroup.add(realCoordinatesRadioButton);
org.openide.awt.Mnemonics.setLocalizedText(realCoordinatesRadioButton, org.openide.util.NbBundle.getMessage(SHPExporterDialog.class, "SHPExporterDialog.realCoordinatesRadioButton.text")); // NOI18N
realCoordinatesRadioButton.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
updateRealFake(evt);
}
});
fakeRealGroup.add(fakeCoordinatesRadioButton);
org.openide.awt.Mnemonics.setLocalizedText(fakeCoordinatesRadioButton, org.openide.util.NbBundle.getMessage(SHPExporterDialog.class, "SHPExporterDialog.fakeCoordinatesRadioButton.text")); // NOI18N
fakeCoordinatesRadioButton.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
updateRealFake(evt);
}
});
org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(SHPExporterDialog.class, "SHPExporterDialog.jLabel2.text")); // NOI18N
longitudeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(SHPExporterDialog.class, "SHPExporterDialog.jLabel3.text")); // NOI18N
latitudeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(fileChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 650, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(filler3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGap(219, 219, 219)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(latitudeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(realCoordinatesRadioButton)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(longitudeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(fakeCoordinatesRadioButton)))
.addGroup(layout.createSequentialGroup()
.addGap(68, 68, 68)
.addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(filler2, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(11, 11, 11)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(realCoordinatesRadioButton)
.addComponent(jLabel2)
.addComponent(longitudeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(fakeCoordinatesRadioButton))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(latitudeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(filler3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 3, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(1, 1, 1)
.addComponent(filler2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(fileChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void updateRealFake(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_updateRealFake
updateVisibility();
}//GEN-LAST:event_updateRealFake
private void fileChooserAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileChooserAction
if (evt.getActionCommand().equals("CancelSelection")) {
this.setVisible(false);
this.dispose();
}
if (evt.getActionCommand().equals("ApproveSelection")) {
this.ok = true;
this.setVisible(false);
dispose();
}
}//GEN-LAST:event_fileChooserAction
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JRadioButton fakeCoordinatesRadioButton;
private javax.swing.ButtonGroup fakeRealGroup;
private javax.swing.JFileChooser fileChooser;
private javax.swing.Box.Filler filler1;
private javax.swing.Box.Filler filler2;
private javax.swing.Box.Filler filler3;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JComboBox latitudeComboBox;
private javax.swing.JComboBox longitudeComboBox;
private javax.swing.JRadioButton realCoordinatesRadioButton;
// End of variables declaration//GEN-END:variables
public boolean showDialog() {
this.longitudeComboBox.setModel(new DefaultComboBoxModel(this.nodeColums));
this.latitudeComboBox.setModel(new DefaultComboBoxModel(this.nodeColums));
final boolean geoFound = this.geoFields[0] != null;
if (geoFound) {
this.longitudeComboBox.setSelectedItem(geoFields[0]);
this.latitudeComboBox.setSelectedItem(geoFields[1]);
}
this.realCoordinatesRadioButton.setSelected(geoFound);
this.fakeCoordinatesRadioButton.setSelected(!geoFound);
fileChooser.setFileFilter(new SHPFilter());
fileChooser.setSelectedFile(new java.io.File("untitled.shp"));
updateVisibility();
setLocationRelativeTo(null);
setVisible(true);
return this.ok;
}
void updateVisibility() {
final boolean enable = realCoordinatesRadioButton.isSelected();
longitudeComboBox.setEnabled(enable);
latitudeComboBox.setEnabled(enable);
}
class SHPFilter extends FileFilter {
@Override
public boolean accept(File f) {
// Auch Unterverzeichnisse anzeigen
if (f.isDirectory()) {
return true;
}
return f.getName().toLowerCase().endsWith(".shp");
}
public String getDescription() {
return "Shape Files (.shp)";
}
}
public AttributeColumn[] getGeoFields() {
return realCoordinatesRadioButton.isSelected() ?
new AttributeColumn[]{(AttributeColumn) longitudeComboBox.getSelectedItem(),
(AttributeColumn) latitudeComboBox.getSelectedItem()} :
new AttributeColumn[]{null, null};
}
public File getFile() {
return fileChooser.getSelectedFile();
}
}